//
//  SceneDelegate.m
//  CLBrowser
//
//  Created by chuck on 2021/6/30.
//

#import "SceneDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

#import "CLVCMain.h"
#import "CLKeyboardHelper.h"
#import "CLMenuHelper.h"
#import "CLWebServer.h"
#import "CLErrorPageHelper.h"
#import "CLSessionRestoreHelper.h"
#import "CLWebViewManager.h"
#import "CLUserDefaults.h"
#import "CLNavigationController.h"

@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)setupTabBarController {
    CLVCMain *rootVc = [[CLVCMain alloc] init];
    CLNavigationController *navi = [[CLNavigationController alloc]initWithRootViewController:rootVc];
    self.window.rootViewController = navi;
}

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){
    
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        [self.window setWindowScene:windowScene];
    } else {
        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    [self.window makeKeyAndVisible];
    [self setupTabBarController];
    if (@available(iOS 13.0, *)) {
        if ([CLUserDefaults boolForKey:CLKeyNightStatus]) {
            [self.window setOverrideUserInterfaceStyle:UIUserInterfaceStyleDark];
        } else {
            [self.window setOverrideUserInterfaceStyle:UIUserInterfaceStyleLight];
        }
    }
}

- (void)windowScene:(UIWindowScene *)windowScene didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation traitCollection:(UITraitCollection *)previousTraitCollection  API_AVAILABLE(ios(13.0)) {
    UIColor *backgroundColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
        return [traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark ? [UIColor whiteColor] : UIColorFromRGB(0x3C3C3C);
    }];
    [self.window setBackgroundColor:backgroundColor];
}

- (void)sceneDidDisconnect:(UIScene *)scene  API_AVAILABLE(ios(13.0)){}


- (void)sceneDidBecomeActive:(UIScene *)scene  API_AVAILABLE(ios(13.0)){}


- (void)sceneWillResignActive:(UIScene *)scene  API_AVAILABLE(ios(13.0)){}


- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){}


- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){}


@end
